// hyb_yl/mysubpages/pages/docorder/docorder.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabitem: ['待接诊', '已接诊', '已结束', '退款单','已取消'],
    docindex: 0,
    page:0,
    pagesize:10,
    orderlist: [{
        'state': 0,
      },
      {
        'state': 1,
      },
      {
        'state': 2,
      },
      {
        'state': 3,
      }
    ],
    ifpay: 1 ,//已支付待接诊
    list:[],
    did:"",
    zid:"",
    doc:"",
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var title = options.title;
    var did = options.did;
    var zid = options.zid;
    var doc = options.doc;
    if(doc != '' && doc != 'undefined' && doc != undefined)
    {
      that.setData({
        doc:doc
      })
    }
    if(did != '' && did != 'undefined' && did != undefined)
    {
      that.setData({
        did:did
      })
    }else if(zid != '' && zid != 'undefined' && zid != undefined)
    {
      that.setData({
        zid:zid
      })
    }
    var keyword = options.keyword;
    that.setData({
      title: title,
      keyword: keyword,
    })
    wx.setNavigationBarTitle({
      title: '订单大厅'
    })
  },
  update_time:function(e){
    var that = this;
    wx.showModal({
      title: '提示',
      content:'是否确认修改',
      success:function(con)
      {
        if(con.confirm)
        {
          wx.navigateTo({
            url: '/hyb_yl/userCommunicate/pages/doctor_detail/doctor_detail?did='+e.currentTarget.dataset.did+'&server='+e.currentTarget.dataset.key_words+'&money=0&hid='+e.currentTarget.dataset.hid+'&keshi_two='+e.currentTarget.dataset.keshi_two+'&tid='+e.currentTarget.dataset.typeid+'&leixing=lvtong&name=预约就诊&zid=&id='+e.currentTarget.dataset.id+'&types=uptime',
          })
        }
      }
    })
  },
  doctab:function(e){
    var that = this;
    var dex = e.currentTarget.dataset.dex;
    that.setData({
      docindex:dex,
      list:[],
      page:0
    })
    that.getOrder(dex)

  },
  getOrder:function(index){
    var that = this;
    var did = that.data.did;
    var doc = that.data.doc;
    if(doc == '')
    {
      app.util.request({
        'url':"entry/wxapp/green.guidance_order",
        data:{
          did:that.data.did,
          keyword:that.data.keyword,
          page:that.data.page,
          pagesize:that.data.pagesize,
          type:index
        },
        success:function(res)
        {
          var page = that.data.page + 1;
          that.setData({
            page:page,
            list:that.data.list.concat(res.data),
          })
        }
      })
    }else
    {
      app.util.request({
        'url':"entry/wxapp/green.baogao_order",
        data:{
          zid:that.data.zid,
          keyword:that.data.keyword,
          page:that.data.page,
          pagesize:that.data.pagesize,
          type:index
        },
        success:function(res)
        {
          var page = that.data.page + 1;
          that.setData({
            page:page,
            list:that.data.list.concat(res.data),
          })
        }
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    var docindex = that.data.docindex;
    that.getOrder(docindex);
  },
  // 绿通接诊
  jiezhen:function(e)
  {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var did  = that.data.did;
    var zid = that.data.zid;
    var doc = that.data.doc;
    if(doc == '1')
    {
      var zid = wx.getStorageSync('zid')
    }else{
      var did = wx.getStorageSync('did')
    }
    
    wx.showModal({
      title: '提示',
      content:"是否确认接诊",
      success:function(con)
      {
        if(con.confirm)
        {
          app.util.request({
            'url':"entry/wxapp/green.order_accept",
            data:{
              id:id,
              did:did,
              zid:zid
            },
            success:function(res){
              wx.showModal({
                title: '提示',
                content:res.data.message,
                showCancel:false,
                success:function(res){
                  that.setData({
                    page:0,
                    list:[]
                  })
                  that.getOrder(that.data.docindex);
                }
              })
              
            }
          })
        }
      
      }
    })
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getchar(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = that.data.zid
    var did = e.currentTarget.dataset.did
    var key_words = e.currentTarget.dataset.key_words
    var j_id = e.currentTarget.dataset.j_id
    var back_orser = e.currentTarget.dataset.back_orser
    var openid = e.currentTarget.dataset.openid
    var ifpay = e.currentTarget.dataset.ifpay
    var docindex = that.data.docindex
    wx.navigateTo({
      url: '/hyb_yl/krecovery/pages/postoperative_ordercont/postoperative_ordercont?id=' + id + '&did=' + did + '&key_words=' + key_words + '&j_id=' + j_id + '&back_orser=' + back_orser + '&openid=' + openid + '&ifpay=' + ifpay + '&doc=1',
    })
  },
  
 
  
})